import requests
import json


headers = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "cache-control": "no-cache",
    "content-type": "application/json",
    "origin": "https://www.jianyu360.cn",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.jianyu360.cn/jylab/supsearch/index.html?keywords=&selectType=title&searchGroup=1",
    "sec-ch-ua": "\"Chromium\";v=\"142\", \"Microsoft Edge\";v=\"142\", \"Not_A Brand\";v=\"99\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0"
}
cookies = {
    "SESSIONID": "c7758ca727164bb93cb3d1f17b8ddcd46af89c08",
    "JYGuestUID": "1990374091902681088",
    "Hm_lvt_52c42de35032567eb9d7a24a43c84bda": "1763377139",
    "HMACCOUNT": "06D1F1816DD4C515",
    "fid": "1c7e75bd6bc024d6e17ddf3cc5d7e4dd",
    "JYTrustedId": "RQxHC1JBUFQHVxdfQloBQlcBBlEQCUMNBkFWB1QBEAtaRE9FCwkBBkNbQFdUTQICBw1FX0hW",
    "eid": "1bo296huMgghgO9bimxe10mjrvyfJeqN3SPuNXdEq+zTX/1XJbyf4MJ6+PaKzc+BuqQEPfZG66O7Q++wweo8ya9JK/ufVBoSvLoAlj/72+oPri0azfP/qGqrHuuphE/WFYu3F0GGCy/plSjXCreA0D0PcvAHDsJ6n+LWa064Bxw=",
    "limitSearchTextFlag": "PnZIB1763377147520467375",
    "token": "nkeGvuWnQFGTdrrWLQ6CBm2ZIItTLz9gq0jyYaJPw+yseMQBNr4tgP2Qu+gp0aBccWi+B2YSnbVfV59tEbwfkvQ6JDdQ5tTddcwkUbYZ4PJc3Z2GNqP7unoFuaaMjbHuUzvaHXOwfxIx0UKyDHpv0u3SWAiRqLVO2uojFOlEYZs=",
    "Hm_lpvt_52c42de35032567eb9d7a24a43c84bda": "1763377222"
}
url = "https://www.jianyu360.cn/jyapi/jybx/core/fType/searchList"
data = {
    "searchGroup": 1,
    "reqType": "lastNews",
    "pageNum": 2,
    "pageSize": 50,
    "keyWords": "",
    "searchMode": 0,
    "bidField": "",
    "publishTime": "1731846840-1763382840",
    "selectType": "title,content",
    "subtype": "",
    "exclusionWords": "",
    "buyer": "",
    "winner": "",
    "agency": "",
    "industry": "",
    "province": "",
    "city": "",
    "district": "",
    "buyerClass": "",
    "fileExists": "",
    "price": "",
    "buyerTel": "",
    "winnerTel": ""
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, cookies=cookies, data=data)

print(response.text)
print(response)

import subprocess
import os

# 解析响应数据
response_json = response.json()
encrypted_data = response_json['data']  # response的data字段
key = response_json['secretKey']  # response的secretKey字段

# 将参数写入临时JS文件
js_dir = r"e:\face_to_work\full-stack-study\python-code\爬虫\JS逆向\JS混淆"
temp_js = os.path.join(js_dir, "temp_decrypt.js")

with open(temp_js, 'w', encoding='utf-8') as f:
    f.write(f"""
const {{ getData }} = require('./02.js');

const encryptedData = `{encrypted_data}`;
const key = `{key}`;

getData(encryptedData, key).then(result => {{
    console.log(result);
}}).catch(err => {{
    console.error('解密失败:', err);
}});
""")

# 调用 Node.js 脚本解密数据
result = subprocess.run(
    ["node", "temp_decrypt.js"],
    capture_output=True,
    text=True,
    cwd=js_dir,
    encoding='utf-8'  # 指定输出编码为 UTF-8
)

# 删除临时文件
os.remove(temp_js)

print("解密后的数据:")
print(result.stdout)
if result.stderr:
    print("错误信息:")
    print(result.stderr)
